<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

/**
 * ctl_cart
 *
 * @uses b2c_frontpage
 * @package
 * @version $Id: ctl.cart.php 1952 2008-04-25 10:16:07Z flaboy $
 * @copyright 2003-2007 ShopEx
 * @author <kxgsy163@163.com>
 * @license Commercial
 */

class whyshopseckill_ctl_site_whyshopseckill extends whyshopseckill_frontpage{


   /* function __construct($app){
        parent::__construct($app);
        $shopname = app::get('site')->getConf('site.name');
        $this->shopname = $shopname;
        if(isset($shopname)){
            $this->title = app::get('b2c')->_('添加秒杀商品').$shopname;
            $this->keywords = app::get('b2c')->_('添加秒杀商品').$shopname;
            $this->description = app::get('b2c')->_('添加秒杀商品').$shopname;
        }
        $this->app_b2c = app::get('b2c');
    }*/


     public function getgoods($id) {
       
        $id=$_POST['id']?$_POST['id']:$id;
        $filter['whyshopseckill_id']=$id;
        //取当前秒杀活动下的所有秒杀商品信息
        $arr_goods = $this->app->model('whyshopseckill_goods')->getList('*',$filter,0,-1); 
      
        $userObject = kernel::single('b2c_user_object');
        $siteMember = $userObject->get_current_member();


        foreach ($arr_goods as $key => $value) {
            # code...
          $filter['goods_id']=$value['seckill_goods_id'];


          $arr_goods_info = app::get('b2c')->model('goods')->getList('*',$filter,0,-1);

          // print_r($arr_goods_info);exit;

          $filter['is_default']='true';
          $arr_product_info = app::get('b2c')->model('products')->getList('*',$filter,0,-1);

            

          $name=$arr_product_info[0]['name'];
          $arr_goods[$key]['goods_name']=$name;


          $products=$arr_product_info[0]['product_id'];
          $arr_goods[$key]['product_id']=$products;


          $mktprice=$arr_goods_info[0]['mktprice'];
          $arr_goods[$key]['goods_mktprice']=$mktprice;

          //  $arr_goods_image = app::get('b2c')->model('goods')->getList('*',$filter,0,-1);
          $image=$arr_goods_info[0]['image_default_id'];
          $arr_goods[$key]['goods_image']=$image;

          $arr_static = $this->app->model('whyshopseckill')->getList('*',$filter,0,-1);  

          $static=$arr_static[0]['seckill_static'];

          $arr_goods[$key]['static']=$static;

          //获取秒杀商品出售情况
          $goods_id=$arr_goods_info[0]['goods_id'];
          $whyshopseckill_id=$id;
          $member_id=$siteMember['member_id'];
          $arr_goods[$key]['member_id']=$member_id;
          $seckill_sum=$this->app->model('whyshopseckill')->getSeckillgoodsnums($goods_id,$whyshopseckill_id,$member_id);

          if ($seckill_sum['total']=='') {
           $seckill_sum['total']=0;
          }
          $sum=$seckill_sum['total'];
          $arr_goods[$key]['sum']=$sum;


          $percent=ceil($arr_goods[$key]['sum']/$arr_goods[$key]['seckill_total']*100);
           $arr_goods[$key]['percent']=$percent;

           //限购2件
            $member_id=$siteMember['member_id'];
            $arr_goods[$key]['member_id']=$member_id;
            $member_purchase=$this->app->model('whyshopseckill')->getSeckillgoodsnumslimit($goods_id,$whyshopseckill_id,$member_id);
            //每个会员购买数量
            $purchase=$member_purchase['total'];
            $arr_goods[$key]['purchase']=$purchase;
        }


         // print_r($arr_goods);exit();
       //echo json_encode($arr_goods);
        // if ($member_id && $purchase<=$seckill_limit ) {
        //   # code...
        // }
        $this->pagedata['arr_goods5']=$arr_goods;




        $this->display('site/whyshopseckill/goods.html');

      }
      public function index() {
          echo 'empty';exit;

       // $this->set_tmpl('whyshopseckill');//
      $arr = $this->app->model('whyshopseckill')->dump($id);



       $seckill_time=$this->app->model('whyshopseckill')->getSeckillTime();

      
      




         // print_r($seckill_time);exit;
       $this->pagedata['whyshopseckill_time'] = $seckill_time;
       $this->pagedata['res_url'] =app::get('whyshopseckill')->res_url;
        $this->set_tmpl('whyshopseckill');
      $this->page('site/whyshopseckill/index.html');   
       // $this->page('site/whyshopseckill/index.html');
     }


     public function index3($id){
       $arr = app::get('b2c')->model('goods')->dump($id);
       $whyshopseckill_info=$this->app->model('whyshopseckill')->getSeckillByGoodsId();        
       $this->pagedata['whyshopseckill_info'] = $whyshopseckill_info;
       $this->pagedata['res_url'] =app::get('whyshopseckill')->res_url;
      $this->page('site/whyshopseckill/index.html');
      // $this->page('site/product/basic.html');
     }

    
   }

